package com.pzhuweb.sgblog.controller;

import com.pzhuweb.sgblog.domain.dto.MenuDto;
import com.pzhuweb.sgblog.domain.entity.Menu;
import com.pzhuweb.sgblog.domain.utils.ResponseResult;
import com.pzhuweb.sgblog.service.SystemMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 鄧浩奇
 * @classname SystemMenuController
 * @description
 * @since 2023/8/23 13:45
 **/

@RestController
@RequestMapping("/system/menu")
@Api(tags = "SystemMenuController",description = "权限菜单增删改查")
public class SystemMenuController {

    @Resource
    private SystemMenuService systemMenuService;

    @ApiOperation(value = "获取菜单树")
    @GetMapping("/treeSelect")
    public ResponseResult<?> treeSelect() {
        return systemMenuService.treeSelect();
    }


    @ApiOperation(value = "根据角色id查询对应的权限菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "角色id",dataTypeClass = Long.class,example = "1",paramType = "path")
    })
    @GetMapping("/roleMenuTreeSelect/{id}")
    public ResponseResult<?> roleMenuTreeSelect(@PathVariable("id") Long id) {
        return systemMenuService.roleMenuTreeSelect(id);
    }


    @ApiOperation(value = "获取权限菜单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "menuName",value = "菜单名称",dataTypeClass = String.class,paramType = "query"),
            @ApiImplicitParam(name = "status",value = "菜单状态",dataTypeClass = String.class,paramType = "query")
    })
    @GetMapping("/list")
    public ResponseResult<?> getMenuList(String menuName, String status) {
        return systemMenuService.getMenuList(menuName, status);
    }

    /*
    * 新增菜单
    * */
    @ApiOperation(value = "新增菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "menuDto",value = "Menu实体类",dataTypeClass = Object.class,paramType = "body"),
    })
    @PostMapping()
    public ResponseResult<?> addMenu(@RequestBody Menu menuDto) {
        return systemMenuService.addMenu(menuDto);
    }



    /*
    * 修改菜单，获取待修改的菜单详情
    * */
    @ApiOperation(value = "根据菜单id获取菜单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "menuId",value = "菜单id",dataTypeClass = Long.class,example = "1",paramType = "path"),
    })
    @GetMapping("/{id}")
    public ResponseResult<?> getMenuDetails(@PathVariable("id") Long menuId) {
        return systemMenuService.getMenuDetails(menuId);
    }




    /*
    * 修改菜单
    * */
    @ApiOperation(value = "修改菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "menuDto",value = "Menu实体类",dataTypeClass = Object.class,paramType = "body"),
    })
    @PutMapping()
    public ResponseResult<?> updateMenu(@RequestBody MenuDto menuDto) {
        return systemMenuService.updateMenu(menuDto);
    }




    /*
    * 删除菜单
    * */
    @ApiOperation(value = "删除菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "menuId",value = "菜单id",dataTypeClass = Long.class,example = "1",paramType = "path"),
    })
    @DeleteMapping("/{id}")
    public ResponseResult<?> deleteMenu(@PathVariable("id") Long menuId) {
        return systemMenuService.deleteMenuById(menuId);
    }
}
